import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-10-18
 * Time:19:55
 */
public class Mystack {
    public int val;
    public int []elem;
    public static final int DEFUALT_SIZE=10;
    public int usesize;

    public Mystack(){
        this.elem=new int[DEFUALT_SIZE];
    }
    public boolean isFull(){
        if(usesize==elem.length){
            return true;
        }
        return false;
    }
    public int push(int val){
        if(isFull()){
            elem= Arrays.copyOf(elem,2*elem.length);
        }
        elem[usesize]=val;
        usesize++;
        return val;
    }
    public int pop(){
        if(usesize==0){
            throw new MyStackException("不存在数组");
        }
        return elem[--usesize];
    }
    public int peek(){
        if(usesize==0){
            throw new MyStackException("不存在数组");
        }
        return elem[usesize-1];
    }
    public boolean empty(){
        if(usesize==0){
            return true;
        }
        return false;
    }

}
